//
//  transitionAnimater.m
//  EFExtend
//
//  Created by mac on 15/3/26.
//  Copyright (c) 2015年 Eric. All rights reserved.
//

#import "transitionAnimater.h"


@interface transitionAnimater ()
@property (nonatomic,strong) HMUITapbarView *toolTab;
@property (nonatomic,strong) UIScrollView   *scroll;
@property (nonatomic,strong) UITableView   *catalog;
@property (nonatomic,strong) UITableView   *info;
@property (nonatomic,strong) UIView *sizingView;
@property (nonatomic,strong) UIView* contentView;
@end

@implementation transitionAnimater

- (void)dealloc
{
    self.info = nil;
    self.catalog = nil;
    self.scroll = nil;
    HM_SUPER_DEALLOC();
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)load{
//    self.allowedLandscape = YES;
//    self.allowedPortrait = NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}
- (BOOL) shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeRight;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.customNavLeftBtn setImagePrefixName:@"back_dk.png" title:nil];
    [self.customNavLeftBtn setFrame:CGRectMakeBound(40, 40)];
    
    [self.customNavRightBtn setImagePrefixName:@"refresh_dk.png" title:nil];
    [self.customNavRightBtn setFrame:CGRectMakeBound(40, 40)];
    
    [self customNavTitleView:self.toolTab];
    
//    [self setNavigationBarOriginalColor:Color_Theme_lightgray noShadow:NO];
    
    [self setNavigationBarTranslucent:NO];
    
    [self createScrollView];
   
    self.sizingView = UIView.new;
    [self.scroll addSubview:_sizingView];
//    _sizingView.backgroundColor = Color_Theme_gray;
    [_sizingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_bottom);
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
        make.width.mas_equalTo(self.contentView.mas_width);
    }];
    
    
    [self createCatalogView];
    
    [self createInfoView];
    
    INFO(self.scroll,self.view,self.catalog,self.info);
    
//    [self loadCatalog:NO];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    //    self.scroll.contentSize = CGSizeMake(2*self.scroll.width, self.scroll.height);
}

- (HMUITapbarView *)toolTab{
    if (_toolTab==nil) {
        _toolTab = [[HMUITapbarView alloc]initWithFrame:CGRectMake(0, 0, 170, 44)];
        _toolTab.barStyle = UITapbarStyleCenter;
        _toolTab.eventReceiver = self;
        UIButten *btn = [_toolTab addItemWithTitle:@"TI_BOOKSELF_CATALOG_calog" imageName:@"catalog_left.png" size:CGSizeMake(85, 38) background:YES];
//        [btn setTitleColor:Color_Theme_light forState:UIControlStateSelected];
//        [btn setTitleColor:Color_Theme_gray forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:16];
        
        //        btn = [_toolTab addItemWithTitle:TXT(@"TI_BOOKSELF_CATALOG_mark") imageName:@"catalog_midle.png" size:CGSizeMake(85, 35) background:YES];
        //        [btn setTitleColor:Color_Theme_light forState:UIControlStateSelected];
        //        [btn setTitleColor:Color_Theme_gray forState:UIControlStateNormal];
        //        btn.titleLabel.font = [UIFont systemFontOfSize:16];
        
        btn = [_toolTab addItemWithTitle:@"TI_BOOKSELF_CATALOG_info" imageName:@"catalog_right.png" size:CGSizeMake(85, 38) background:YES];
//        [btn setTitleColor:Color_Theme_light forState:UIControlStateSelected];
//        [btn setTitleColor:Color_Theme_gray forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    return _toolTab;
}

- (void)createScrollView{
    //页面切换
    self.scroll = [[UIScrollView alloc]init];
    self.scroll.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.scroll];
    self.scroll.pagingEnabled = YES;
    self.scroll.showsHorizontalScrollIndicator = NO;
    self.scroll.delegate = self;
    [self.scroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    
    self.contentView = UIView.new;
    [self.scroll addSubview:self.contentView];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.scroll.mas_top).offset(0);
        make.left.mas_equalTo(self.scroll.mas_left).offset(0);
        make.height.mas_equalTo(self.view.mas_height);
        make.width.mas_equalTo(self.view.mas_width).multipliedBy(2);
    }];
}

- (void)createCatalogView{
    self.catalog = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    [self.contentView addSubview:self.catalog];
    self.catalog.delegate = self;
    self.catalog.dataSource = self;
    self.catalog.backgroundColor = [UIColor clearColor];
    
    [self.catalog mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).offset(0);
        make.height.mas_equalTo(self.view.mas_height).offset(0);
        make.left.mas_equalTo(self.contentView.mas_left).offset(0);
        make.width.mas_equalTo(self.view.mas_width).offset(0);
    }];
}

- (void)createInfoView{
    self.info = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    [self.contentView addSubview:self.info];
    self.info.delegate = self;
    self.info.dataSource  = self;
    self.info.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.info.backgroundColor = [UIColor clearColor];
    [self.info mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).offset(0);
        make.height.mas_equalTo(self.view.mas_height).offset(0);
        make.left.mas_equalTo(self.catalog.mas_right).offset(0);
        make.width.mas_equalTo(self.view.mas_width).offset(0);
    }];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

ON_Button(signal){
    UIButten *btn = signal.source;
    if ([signal is:[UIButten TOUCH_UP_INSIDE]]) {
        if ([btn is:@"leftBtn"]) {//customNavLeftBtn
            [self backAndRemoveWithAnimate:YES];
        }else if ([btn is:@"rightBtn"]){//customNavRightBtn
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }
}

ON_WebAPI(dlg){
    if (dlg.sending) {
        
        
    }else if (dlg.succeed){
//        NSDictionary *dic = [dlg.output objectForKey:[HMWebAPI params]];
        
        
    }else if (dlg.failed){
        if (dlg.timeout) {
            [self showFailureTip:@"操作失败" detail:@"链接超时" timeOut:3.f];
            return;
        }
        
        [self showFailureTip:@"网络链接失败" detail:@"数据不存在或网络错误" timeOut:3.f];
    }else if (dlg.cancelled){
        
    }
//#if (__ON__ == __HM_DEVELOPMENT__)
//    CC( [self.class description],dlg.responseData?dlg.responseData:dlg.errorDesc);
//#endif	// #if (__ON__ == __BEE_DEVELOPMENT__)
}
@end
